package camel.corp.universalcopy;

import a.f.i.a.c;
import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.ActivityOptions;
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.Rect;
import android.os.Build;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import androidx.core.app.j;
import com.camel.corp.universalcopy.CopyTileService;
import com.camel.corp.universalcopy.E;
import com.camel.corp.universalcopy.SwitchAppWidgetProvider;
import com.camel.corp.universalcopy.UniversalCopyService;
import com.camel.corp.universalcopy.ha;
import com.camel.corp.universalcopy.ia;
import com.camel.corp.universalcopy.ja;
import com.camel.corp.universalcopy.ka;
import com.camel.corp.universalcopy.ma;
import com.crashlytics.android.Crashlytics;
import java.util.ArrayList;

public class UniversalCopyService extends AccessibilityService {
  private int a = 0;
  
  private int b = 0;
  
  private long c = 0L;
  
  private b d;
  
  private a e;
  
  private Handler f;
  
  private int g = 0;
  // what the fuck is the c?
  private ArrayList<E> a(c paramc, int paramInt1, int paramInt2, int paramInt3) {// so here is the thing.
      // WTF is that E?
    ArrayList arrayList = new ArrayList();
    // what can you fucking return?
    if (paramc != null) {
      if (paramc.v() == null)
        return arrayList; 
      if (paramInt3 < 50) {
        int i;// recursion_MAX=50
        // child?
//          AddAll是传入一个List，将此List中的所有元素加入到当前List中，也就是当前List会增加的元素个数为传入的List的大小
          // why you have a plus-one?
          // depth?
        for (i = paramc.b() - 1; i >= 0; i--)
          arrayList.addAll(a(paramc.b(i), paramInt1, paramInt2, paramInt3 + 1)); 
      } 
      if (paramc.c() != null && paramc.c().equals("android.webkit.WebView"))
        return arrayList; 
      CharSequence charSequence1 = paramc.d();
      // where are they being defined?
      boolean bool = a(charSequence1);
      CharSequence charSequence2 = null;
      if (bool)
        charSequence1 = null; 
      CharSequence charSequence3 = paramc.g();
      if (!a(charSequence3))
        charSequence1 = charSequence3; 
      if (charSequence1 != null && !"WebView".equals(charSequence1.toString())) {
        if ("Live chat".equals(charSequence1.toString()))
          return arrayList;
        // just receive it yourself?
          // but it is internal call.
          // do it yourself.
        Rect rect = new Rect();
        paramc.b(rect);
        if (this.g < 10000 && a(rect, paramInt1, paramInt2)) {
          CharSequence charSequence = paramc.c();
          if (charSequence == null) {
            charSequence = charSequence2;
          } else {
            charSequence = charSequence.toString();
          } 
          arrayList.add(new E(rect, charSequence1, charSequence));
          this.g++;
        } 
      } 
    } 
    return arrayList;
  }
  
  private void a() {
    NotificationManager notificationManager = (NotificationManager)getSystemService("notification");
    String str2 = getString(2131755042);
    String str1 = getString(2131755163);
    NotificationChannel notificationChannel = new NotificationChannel("uc_copy_mode_channel", str2, 1);
    notificationChannel.setDescription(str1);
    notificationChannel.setLockscreenVisibility(-1);
    notificationChannel.setShowBadge(false);
    notificationManager.createNotificationChannel(notificationChannel);
  }
  
  private void a(int paramInt) { b(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("ocr_mode_active", false), paramInt); }
  
  public static void a(Context paramContext) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(paramContext);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    if (sharedPreferences.getBoolean("service_active", false))
      editor.remove("accessibility_service_has_been_created"); 
    editor.putBoolean("accessibility_active", false).putBoolean("service_active", false).commit();
    b(paramContext);
  }
  
  private void a(boolean paramBoolean, int paramInt) {
    boolean bool;
    AccessibilityServiceInfo accessibilityServiceInfo = getServiceInfo();
    if (accessibilityServiceInfo == null) {
      Log.e("universal_copy", "Failed to change flag, service info was null");
      return;
    } 
    if ((accessibilityServiceInfo.flags & paramInt) != 0) {
      bool = true;
    } else {
      bool = false;
    } 
    if (bool == paramBoolean)
      return; 
    if (paramBoolean) {
      accessibilityServiceInfo.flags |= paramInt;
    } else {
      accessibilityServiceInfo.flags &= (paramInt ^ 0xFFFFFFFF);
    } 
    setServiceInfo(accessibilityServiceInfo);
  }
  
  private boolean a(Rect paramRect, int paramInt1, int paramInt2) { return (paramRect.bottom >= 0 && paramRect.right >= 0 && paramRect.top <= paramInt2 && paramRect.left <= paramInt1); }
  
  private boolean a(CharSequence paramCharSequence) { return (paramCharSequence != null) ? "".equals(paramCharSequence.toString().replaceAll("\\s", "")) : 1; }
  
  private void b() { ((NotificationManager)getSystemService("notification")).cancel(0); }
  
  public static void b(Context paramContext) {
    SwitchAppWidgetProvider.a(paramContext);
    if (Build.VERSION.SDK_INT >= 24)
      CopyTileService.a(paramContext); 
  }
  
  private void b(boolean paramBoolean, int paramInt) {
    Intent intent;
    String str = null;
    try {
      intent = getRootInActiveWindow();
    } catch (Exception null) {
      Crashlytics.a(intent);
      intent = null;
    } 
    if (intent != null) {
      String str1 = String.valueOf(intent.getPackageName());
      str = str1;
      if (paramInt != 0) {
        str = str1;
        if (this.b < 10) {
          Rect rect = new Rect();
          intent.getBoundsInScreen(rect);
          int i = Math.abs(rect.right - rect.left);
          if (Math.abs(rect.top - rect.bottom) >= i) {
            i = 1;
          } else {
            i = 2;
          } 
          str = str1;
          if (i != paramInt) {
            Log.d("universal_copy", "Retrying for orientation");
            this.b++;
            this.f.postDelayed(new ja(this, paramBoolean, paramInt), 100L);
            return;
          } 
        } 
      } 
    } 
    if (paramBoolean) {
      intent = new Intent(this, com.camel.corp.universalcopy.screenshot.ScreenshotActivity.class);
      intent.putExtra("source_package", str);
      intent.setFlags(268435456);
      intent.addFlags(536870912);
      if (!"com.camel.corp.universalcopy".equals(str))
        intent.addFlags(32768); 
      startActivity(intent);
      this.a = 0;
      this.b = 0;
      return;
    } 
    if (this.a < 10) {
      Log.d("universal_copy", "Trying start of universal copy mode");
      if (intent == null || (str != null && str.contains("com.android.systemui"))) {
        this.a++;
        this.f.postDelayed(new ka(this, paramInt), 100L);
        return;
      } 
      WindowManager windowManager = (WindowManager)getSystemService("window");
      paramInt = ma.a(windowManager);
      int i = ma.b(windowManager);
      c c1 = c.a(intent);
      this.g = 0;
      String str1 = a(c1, i, paramInt, 0);
      Intent intent1 = new Intent(this, com.camel.corp.universalcopy.CopyActivity.class);
      intent1.setFlags(268435456);
      intent1.addFlags(536870912);
      if (!"com.camel.corp.universalcopy".equals(str))
        intent1.addFlags(32768);
      // hey! here's the shit. the fuckling array list?
      // but what the fuck is this?
      intent1.putParcelableArrayListExtra("copy_nodes", str1);
      intent1.putExtra("source_package", str);
      startActivity(intent1, ActivityOptions.makeCustomAnimation(getBaseContext(), 2130771968, 2130771969).toBundle());
      Application application = getApplication();
      if (str1.size() > 0) {
        String str2 = "UC_MODE_SUCCEED";
      } else {
        str1 = "UC_MODE_FAILED";
      } 
      ma.a(application, "APP_DATA", str1, str);
    } 
    this.a = 0;
    this.b = 0;
  }
  
  private void c() {
    j.d d1 = new j.d(this, "uc_copy_mode_channel");
    d1.c(2131230855);
    d1.a(null);
    d1.c(getResources().getString(2131755042));
    d1.b(getResources().getString(2131755148));
    d1.d(-1);
    d1.b(-2);
    d1.a(getResources().getColor(2131099693));
    d1.c(true);
    d1.a(false);
    Intent intent = new Intent("UNIVERSAL_COPY_SHOW_OVERLAY");
    intent.putExtra("TRIGGER_TYPE", "UC_NOTIFICATION_BUTTON");
    d1.a(PendingIntent.getBroadcast(this, 0, intent, 0));
    ((NotificationManager)getSystemService("notification")).notify(0, d1.a());
  }
  
  private void d() { a(0); }
  
  public void onAccessibilityEvent(AccessibilityEvent paramAccessibilityEvent) {
    if (paramAccessibilityEvent.getEventType() == 2 && "com.android.systemui".equals(paramAccessibilityEvent.getPackageName())) {
      SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
      String str = sharedPreferences.getString("long_click_button", "NONE");
      if (str.equals(paramAccessibilityEvent.getContentDescription()) && sharedPreferences.getBoolean("service_active", false))
        this.f.postDelayed(new ha(this, str), 100L); 
    } 
  }
  
  public void onCreate() {
    super.onCreate();
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    boolean bool1 = sharedPreferences.getBoolean("service_active", false);
    boolean bool2 = sharedPreferences.getBoolean("notification_active", true);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    if (!sharedPreferences.getBoolean("accessibility_service_has_been_created", false)) {
      editor.putBoolean("service_active", true);
      editor.putBoolean("accessibility_service_has_been_created", true);
      ma.a(getApplication(), "SETTINGS", "ACCESSIBILITY_ACTIVATED");
      bool1 = true;
    } 
    if (Build.VERSION.SDK_INT >= 26)
      a(); 
    editor.putBoolean("accessibility_active", true).commit();
    b(getApplicationContext());
    this.e = new a(this, null);
    IntentFilter intentFilter = new IntentFilter("UNIVERSAL_COPY_SHOW_OVERLAY");
    intentFilter.addAction("UNIVERSAL_COPY_DISABLE");
    intentFilter.addAction("UNIVERSAL_COPY_ACTIVATE");
    intentFilter.addAction("UNIVERSAL_COPY_TOGGLE_KEYWATCHER");
    registerReceiver(this.e, intentFilter);
    this.f = new Handler();
    if (bool1 && bool2)
      this.f.postDelayed(new ia(this), 3000L); 
  }
  
  public void onDestroy() {
    a(getApplicationContext());
    b();
    unregisterReceiver(this.e);
    super.onDestroy();
  }
  
  public void onInterrupt() {}
  
  protected boolean onKeyEvent(KeyEvent paramKeyEvent) { // Byte code:
    //   0: aload_0
    //   1: invokevirtual getApplicationContext : ()Landroid/content/Context;
    //   4: invokestatic getDefaultSharedPreferences : (Landroid/content/Context;)Landroid/content/SharedPreferences;
    //   7: astore #5
    //   9: aload #5
    //   11: ldc_w 'long_click_button'
    //   14: ldc_w 'NONE'
    //   17: invokeinterface getString : (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    //   22: astore #6
    //   24: aload #6
    //   26: invokestatic parseInt : (Ljava/lang/String;)I
    //   29: istore #4
    //   31: aload_1
    //   32: invokevirtual getKeyCode : ()I
    //   35: iload #4
    //   37: if_icmpne -> 207
    //   40: iconst_1
    //   41: istore_2
    //   42: goto -> 45
    //   45: iload_2
    //   46: istore_3
    //   47: iload #4
    //   49: sipush #187
    //   52: if_icmpne -> 80
    //   55: iload_2
    //   56: ifne -> 78
    //   59: aload_1
    //   60: invokevirtual getKeyCode : ()I
    //   63: istore_2
    //   64: iload_2
    //   65: bipush #82
    //   67: if_icmpne -> 73
    //   70: goto -> 78
    //   73: iconst_0
    //   74: istore_3
    //   75: goto -> 80
    //   78: iconst_1
    //   79: istore_3
    //   80: iload_3
    //   81: ifeq -> 198
    //   84: aload_0
    //   85: getfield d : Lcom/camel/corp/universalcopy/UniversalCopyService$b;
    //   88: ifnonnull -> 104
    //   91: aload_0
    //   92: new com/camel/corp/universalcopy/UniversalCopyService$b
    //   95: dup
    //   96: aload_0
    //   97: aconst_null
    //   98: invokespecial <init> : (Lcom/camel/corp/universalcopy/UniversalCopyService;Lcom/camel/corp/universalcopy/ha;)V
    //   101: putfield d : Lcom/camel/corp/universalcopy/UniversalCopyService$b;
    //   104: aload_1
    //   105: invokevirtual getAction : ()I
    //   108: iconst_1
    //   109: if_icmpne -> 146
    //   112: aload_1
    //   113: invokevirtual getEventTime : ()J
    //   116: aload_0
    //   117: getfield c : J
    //   120: lsub
    //   121: ldc2_w 400
    //   124: lcmp
    //   125: ifge -> 139
    //   128: aload_0
    //   129: getfield f : Landroid/os/Handler;
    //   132: aload_0
    //   133: getfield d : Lcom/camel/corp/universalcopy/UniversalCopyService$b;
    //   136: invokevirtual removeCallbacks : (Ljava/lang/Runnable;)V
    //   139: aload_0
    //   140: lconst_0
    //   141: putfield c : J
    //   144: iconst_0
    //   145: ireturn
    //   146: aload_1
    //   147: invokevirtual getAction : ()I
    //   150: ifne -> 198
    //   153: aload #5
    //   155: ldc 'service_active'
    //   157: iconst_0
    //   158: invokeinterface getBoolean : (Ljava/lang/String;Z)Z
    //   163: ifeq -> 198
    //   166: aload_0
    //   167: aload_1
    //   168: invokevirtual getEventTime : ()J
    //   171: putfield c : J
    //   174: aload_0
    //   175: getfield d : Lcom/camel/corp/universalcopy/UniversalCopyService$b;
    //   178: iload #4
    //   180: invokevirtual a : (I)V
    //   183: aload_0
    //   184: getfield f : Landroid/os/Handler;
    //   187: aload_0
    //   188: getfield d : Lcom/camel/corp/universalcopy/UniversalCopyService$b;
    //   191: ldc2_w 400
    //   194: invokevirtual postDelayed : (Ljava/lang/Runnable;J)Z
    //   197: pop
    //   198: aload_0
    //   199: aload_1
    //   200: invokespecial onKeyEvent : (Landroid/view/KeyEvent;)Z
    //   203: ireturn
    //   204: astore_1
    //   205: iconst_0
    //   206: ireturn
    //   207: iconst_0
    //   208: istore_2
    //   209: goto -> 45
    // Exception table:
    //   from	to	target	type
    //   24	40	204	java/lang/NumberFormatException
    //   59	64	204	java/lang/NumberFormatException }
  
  protected void onServiceConnected() {
    super.onServiceConnected();
    int i = Build.VERSION.SDK_INT;
    boolean bool = true;
    if (i >= 21)
      a(true, 64); 
    if (Build.VERSION.SDK_INT >= 18) {
      str = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("long_click_button", "NONE");
      try {
        Integer.parseInt(str);
      } catch (NumberFormatException str) {
        bool = false;
      } 
      a(bool, 32);
    } 
  }
}


/* Location:              D:\Users\alienware\AndroidStudioProjects\Lazero\sample\sampler\classes-dex2jar\com\camel.jar!\camel\cor\\universalcopy\UniversalCopyService.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       1.0.7
 */